'''urllib_爬虫异常'''

import urllib.request
import urllib.error

csdn_url = 'https://blog.csdn.net/weixin_44799217/article/details/1122562200'
csdn_headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36'
}

try:
    request = urllib.request.Request(url=csdn_url, headers=csdn_headers)
    response = urllib.request.urlopen(request)
    content = response.read().decode('utf-8')
    print(content)
except urllib.error.HTTPError:
    print('请求地址出现：HTTPError 异常')
except urllib.error.URLError:
    print('请求地址有误！ URLError')

